import request from '../request'
import store from '../../store'
import router from '../../router'
import utils from '../../utils'
/***
 * 通用登录接口
 * developer:wos / 2019-12-28
 */
async function login( data = utils.throwIfMissing() ) {
    //规范化判断
    if( !('userName' in data) || !('passWord' in data) ){
        return '请输入用户名或密码'
    }

    let res = await request({
        url: '/sys/login?a=1',
        method: 'post',
        data
    })
    if (res) {
        if (res.code === 200){
            store.state.TOKEN = res.data.token
            store.state.USER_DATA = res.data
            // console.log('addRoutes的路由配置', store.getters.ROUTERS_CONFIG )
console.log( store.getters.ROUTERS_CONFIG )
            await router.addRoutes( store.getters.ROUTERS_CONFIG ) //路由配置
            store.state.MENU_CONFIG =  store.getters.MENU_CONFIG // 菜单配置
            return true
        }else{
            return res.msg
        }
    }else{
        return false
    }
}


export default login